<div class="container">
    
    <?php $att = array('class' => 'form-horizontal', 'role' => 'form'); echo form_open('', $att);?>
    <input type="hidden" name="id" id="id" value="<?php echo $id;?>" />
    <div class="col-md-6">
        <div class="row">
            <div class="col-md-12">
              <div class="panel">
                <div id="pop_upload" style="position: absolute;width: 100%;height: 100%;z-index: 999;display: none">
                    <p style="text-align: center;width: 100%;height: 100%;background: #CCC;padding-top: 45%;color: #990000;font-size: 25px;">Đang upload ảnh ...</p>
                </div>
                <div class="panel-heading">
                  <div class="panel-title"> <span class="glyphicon glyphicon-pencil"></span> Sửa menu </div>
                </div>
                <div class="panel-body">
                    <?php if(isset($result) || validation_errors()):?>
                    <div class="alert alert-danger alert-dismissable">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                             <?php if(isset($result)){echo $result;}?>
                            <?php echo validation_errors(); ?>
                    </div>
                    <?php endif;?>
                    <div class="form-group">
                      <label for="inputStandard" class="col-lg-2 control-label">Tên menu</label>
                      <div class="col-lg-10">
                        <input type="text" id="nameMenu" name="nameMenu" class="form-control" value="<?php echo $data->title?>" placeholder="Tên menu">
                      </div>
                    </div>
                    <div class="form-group">
                      <label for="inputPassword" class="col-lg-2 control-label">Thuộc menu</label>
                      <div class="col-lg-10">
                        <select class="form-control" id="standard-list1" name="menu">
                          <option value="">Chọn menu</option>
                          <option value="0">Đây là menu cha</option>
                          <?php echo $parent;?>
                        </select>
                      </div>
                    </div>
                    <div class="form-group">
                      <label for="inputPassword" class="col-lg-2 control-label">Thuộc danh mục</label>
                      <div class="col-lg-10">
                        <select class="form-control typelink" id="standard-list1" name="typeLink" onchange="getAllLink('',1,'')">
                          <option value="">Chọn loại link liên kết</option>
                          <?php echo $typelink;?>
                        </select>
                      </div>
                    </div>
                    <div class="form-group">
                      <label for="inputPassword" class="col-lg-2 control-label">Link hiện tại</label>
                      <div class="col-lg-10">
                        <a target="_blank" href="<?php echo $baseurl.$data->link_menu?>">
                            <?php echo $baseurl.$data->link_menu?>
                        </a>
                      </div>
                    </div>
                    <div class="form-group" id="select_show" style="display:none">
                      <label for="inputPassword" class="col-lg-2 control-label">Chọn link</label>
                      <div class="col-lg-10"  id="select_link">
                        
                      </div>
                    </div>
                  
                </div>
              </div>
            </div>
        </div>
    </div>
    <div class="col-md-3-3">
        <div class="row">
            <div class="col-md-12">
                 <div class="panel">
                    <div class="panel-heading">
                      <div class="panel-title">Hành động</div>
                    </div>
                    <div class="panel-body">
                      <div class="form-group">
                          <div class="col-lg-10" style="width: 100%;">
                          <!-- <label for="img" style="cursor: pointer;width: 100% !important;">
                            <div class="console-btn">
                            
                              <div class="console-icon divider-right"> <span class="glyphicon glyphicon-open"></span> </div>
                              <div class="console-text">
                               
                                <div class="console-subtitle">
                                Ảnh địa diện
                                </div>
                                <div class="console-title">
                                <input type="file" name="img" id="img" value="" onchange="convertimg()" style="display: none;" />
                                <input type="text" name="img_hidden" id="img_hidden" value="" style="display: none;" />
                                
                                <label for="img" style="position: absolute;cursor: pointer">Chọn ảnh</label>
                                </div>
                              </div>
                              
                              <div class="clearfix"></div>
                              <img id="img_show" src="<?php echo $baseurl.'public/upload/images/default.png'?>" style="width: 100%;" />
                            </div>
                            </label>
                            -->
                            <button type="submit" class="btn btn-info btn-gradient btn-sm">Lưu lại</button>
                            <button type="button" class="btn btn-default btn-gradient btn-sm" onclick="window.location='<?php echo $baseurl.'manage/menu.html'?>'">Hủy bỏ</button>
                          </div>
                        </div>
                    </div>  
                 </div>
            </div>
        </div>
    </div>
    </form>
</div>
<script>
getAllLink(<?php echo $data->id_link?>,3,$(".typelink").val());
function getAllLink(id,type,editmenu)
{
    var arr = ['', null, undefined];
    if(in_array(id, arr) == false)
    {
        typelink = id;
    }else{
        typelink = $(".typelink").val();
    }
    type = type;
    $.ajax({
        type: 'POST',
        url: '<?php echo $baseurl.'manage/getalllink'?>',
        data: ({id: typelink, type: type,editmenu: editmenu}),
        success: function(data)
        {
            $("#select_link").html(data);
            $("#select_show").show();
        }
    });
}

function convertimg()
{
    var chose = chose;
    var filesSelected = document.getElementById("img").files;
    if (filesSelected.length > 0)
    {
        var fileToLoad = filesSelected[0];

        var fileReader = new FileReader();

        fileReader.onload = function(fileLoadedEvent) 
        {
            var textAreaFileContents = document.getElementById
            (
                "textAreaFileContents"
                );
            $("#img_hidden").attr('value', fileLoadedEvent.target.result);
            $("#img_show").attr('src', fileLoadedEvent.target.result);
            
            
        };

        fileReader.readAsDataURL(fileToLoad);
    }
}
function in_array(param_1, array) {
    var count = array.length;
    for(var i = 0; i < count; i++) {
        if(array[i] == param_1) return true; // nếu trùng thì trả về true
    }
    return false;
}
</script>